package com.example.apps

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.apps.entity.AppMuiltEntity
import com.example.lib_adapter.BaseQuickMultipleAdapter
import com.example.lib_adapter.BaseViewHolder
import com.example.lib_adapter.MutipleEntity

class NetAdapter:BaseQuickMultipleAdapter<AppMuiltEntity,BaseViewHolder>() {
    override fun getMutipleSpanSize(position: Int, recyclerView: RecyclerView): Int {
        val layoutManager = recyclerView.layoutManager
        if(layoutManager !is GridLayoutManager){
            return 1
        }
        if(data[position].getType()==1){
            return layoutManager.spanCount
        }
        return 1
    }

    override fun createItemView(viewType: Int, parent: ViewGroup): View {
        if(viewType==1){
            return LayoutInflater.from(parent.context).inflate(R.layout.itemnet_1,parent,false)
        }else{
            return LayoutInflater.from(parent.context).inflate(R.layout.itemnet_2,parent,false)
        }
    }

    override fun convert(holder: BaseViewHolder, t: MutipleEntity) {
        val entity = t as AppMuiltEntity
        if(t.getType()==1){
            holder.setText(R.id.tv_type,entity.title)
        }else{
            holder.setText(R.id.net_name,entity.appName)
            holder.setImage(R.id.net_iv,entity.appIcon)
        }
    }

    override fun getItemViewType(position: Int): Int {
        return data.get(position).getType()
    }
}